import { HashRouter, Switch } from "react-router-dom"
import PermissionRoute from "../components/permission/PermissionRoute"
import { paths } from "./path"
import useLoginModel from "../model/useLoginModel";
import { Spin } from "antd";

const RouteItem = () => {
    return paths.map((item, index) => <PermissionRoute key={`PermissionRoute${index}`} path={item.path} component={item.view} exact={item.exact} />)
}

const Routes = () => {
    const { mobileLoading, passwordLoading } = useLoginModel()
    const spinning = mobileLoading || passwordLoading
    return <Spin delay={200} spinning={spinning} tip="加载中...">
        <HashRouter>
            <Switch>
                {RouteItem()}
            </Switch>
        </HashRouter>
    </Spin>
}

export default Routes